home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Megadoom II
/
MEGADOOM II - iso.7z
/
MEGADOOM II.ISO
/
doom
/
network
/
serial6
/
connect.c
next >
Wrap
Text File
|
1994-11-12
|
2KB
|
109 lines
void Connect (void)
{
struct time time;
int oldsec;
int localstage, remotestage;
char str[20];
char idstr[7];
char remoteidstr[7];
unsigned long idnum;
int i;
//
// wait for a good packet
//
printf (STR_ATTEMPT"\n");
//
// build a (hopefully) unique id string by hashing up the current milliseconds
// and the interrupt table
//
if (CheckParm ("-player1"))
idnum = 0;
else if (CheckParm ("-player2"))
idnum = 999999;
else
{
gettime (&time);
idnum = time.ti_sec*100+time.ti_hund;
for (i=0 ; i<512 ; i++)
idnum += ((unsigned far *)0)[i];
idnum %= 1000000;
}
idstr[0] = '0' + idnum/ 100000l;
idnum -= (idstr[0]-'0')*100000l;
idstr[1] = '0' + idnum/ 10000l;
idnum -= (idstr[1]-'0')*10000l;
idstr[2] = '0' + idnum/ 1000l;
idnum -= (idstr[2]-'0')*1000l;
idstr[3] = '0' + idnum/ 100l;
idnum -= (idstr[3]-'0')*100l;
idstr[4] = '0' + idnum/ 10l;
idnum -= (idstr[4]-'0')*10l;
idstr[5] = '0' + idnum;
idstr[6] = 0;
//
// sit in a loop until things are worked out
//
// the packet is: ID000000_0
// the first field is the idnum, the second is the acknowledge stage
// ack stage starts out 0, is bumped to 1 after the other computer's id
// is known, and is bumped to 2 after the other computer has raised to 1
//
oldsec = -1;
localstage = remotestage = 0;
do
{
while ( bioskey(1) )
{
if ( (bioskey (0) & 0xff) == 27)
Error ("\n\n"STR_NETABORT);
}
if (ReadPacket ())
{
packet[packetlen] = 0;
printf ("read : %s\n",packet);
if (packetlen != 10)
continue;
if (strncmp(packet,"ID",2) )
continue;
if (!strncmp (packet+2,idstr,6))
Error ("\n\n"STR_DUPLICATE);
strncpy (remoteidstr,packet+2,6);
remotestage = packet[9] - '0';
localstage = remotestage+1;
oldsec = -1;
}
gettime (&time);
if (time.ti_sec != oldsec)
{
oldsec = time.ti_sec;
sprintf (str,"ID%s_%i",idstr,localstage);
WritePacket (str,strlen(str));
printf ("wrote: %s\n",str);
}
} while (localstage < 2);
//
// decide who is who
//
if (strcmp(remoteidstr,idstr) > 0)
doomcom.consoleplayer = 0;
else
doomcom.consoleplayer = 1;
//
// flush out any extras
//
while (ReadPacket ())
;
}